
let addNewItem = document.querySelector('#addNewItem');
let login_bg = document.querySelector('.login-bg');
let new_item_detail = document.querySelector('.new_item_detail');
let close = document.querySelector('.close');
let cancel = document.querySelector('.cancel');
addNewItem.addEventListener('click',function (){
    login_bg.style.display = 'block';
    new_item_detail.style.display = 'block';
})

close.addEventListener('click',function (){
    login_bg.style.display = 'none';
    new_item_detail.style.display = 'none';
})
cancel.addEventListener('click',function (){
    login_bg.style.display = 'none';
    new_item_detail.style.display = 'none';
})

let itemId = document.querySelector('.itemid');
let productId = document.querySelector('.productid');
let listPrice = document.querySelector('.listprice');
let unitCost = document.querySelector('.unitcost');
let supplier = document.querySelector('.supplier');
let status = document.querySelector('.status');
let attr1 = document.querySelector('.attr1');
let attr2 = document.querySelector('.attr2');
let attr3 = document.querySelector('.attr3');
let attr4 = document.querySelector('.attr4');
let attr5 = document.querySelector('.attr5');
let amount = document.querySelector('.amount');
let productName = document.querySelector('.productName');

let itemListTable = document.querySelector('#itemListTable');

let add = document.querySelector('#add');
add.addEventListener('click',function (){
    console.log("2333")
    if (add.innerText === 'Add new item'){
        console.log("6666")
        var newHtml = '<td>';
        newHtml += itemId.value;
        newHtml += '</td><td>';
        newHtml += productId.value;
        newHtml += '</td><td>';
        newHtml += attr1.value;
        newHtml += attr2.value;
        newHtml += attr3.value;
        newHtml += attr4.value;
        newHtml += attr5.value;
        newHtml += productName.innerText;
        newHtml += '</td><td>¥';
        newHtml += listPrice.value;
        newHtml += '</td><td><a href="item?itemId=';
        newHtml += itemId.value;
        newHtml += '" class="Button">Revise information</a></td>';

        let new_item = document.createElement('tr');
        new_item.innerHTML = newHtml;
        itemListTable.appendChild(new_item);
    }
    login_bg.style.display = 'none';
    new_item_detail.style.display = 'none';
    $.ajax({
        type :'GET',
        url :'http://localhost:8080/addItem?='+resultNum,
        success:function (data){
            console.log(data)
        },
        error:function (errorMsg){
            console.log(errorMsg)
        }
    });
})
